function prefix(x){return x < 10 ? ('0' + x): x }
/**
 * 时间戳格式化
 */
export function formatData(timeStamp,params = {}){
    var time = new Date(parseInt(timeStamp));
    let y = time.getFullYear();
    let m = time.getMonth()+1;
    let d = time.getDate();
    let h = time.getHours();
    let min = time.getMinutes();
    let s = time.getSeconds();
    return params.type ? y + '/' + prefix(m) + '/' + prefix(d) + ' ' + prefix(h) + ':' + prefix(min) + ":" + prefix(s) 
                       : y + '/' + prefix(m) + '/' + prefix(d);

 }

/**
 * 剩余时间倒计时
 */
export function leftTime(year,month,day,hour,minute,second){
    let timer = (new Date(year,month - 1,day,hour,minute,second)) - (new Date()); //计算剩余的毫秒数
    let days = parseInt(timer / 1000 / 60 / 60 / 24 , 10); //计算剩余的天数 
    let hours = parseInt(timer / 1000 / 60 / 60 % 24 , 10); //计算剩余的小时 
    let minutes = parseInt(timer / 1000 / 60 % 60, 10);//计算剩余的分钟 
    let seconds = parseInt(timer / 1000 % 60, 10);//计算剩余的秒数 
    days = prefix(days); 
    hours = prefix(hours); 
    minutes = prefix(minutes); 
    seconds = prefix(seconds); 
    document.getElementById("timer").innerHTML = days+"天" + hours+"小时" + minutes+"分"+seconds+"秒"; 
    setInterval(() => {
        leftTime(year,month,day,hour,minute,second)
    },1000) 
}

/**
 * 分页
 */

 /**
  * 笔记章节
  */
export const cascaderData = (allPartArr) => {
    const data = []
    if(!allPartArr.length) return []
    for(let i = 0; i < allPartArr.length; i++){
        const obj = Object.create({})
        obj.label = `第${i+1}章`
        obj.value = allPartArr[i].id
        obj.children = []
        if(allPartArr[i].videos){
            for(let j = 0; j < allPartArr[i].videos.length; j++){
                obj.children.push({
                    label:`第${j+1}节`,
                    value:allPartArr[i].videos[j].id,
                    link:allPartArr[i].videos[j].link,
                    duration:allPartArr[i].videos[j].duration,
                })
            }
        }
        data.push(obj)
    }
    return data
}